<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../../css/reset.css" />
		<link rel="stylesheet" type="text/css" href="../../../../common/js/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="../../../../common/js/bootstrap-3.3.7-dist/css/bootstrap-theme.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/store_member/style.css" />

		<script src="../../../js/jquery-2.2.3.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/flexible.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../../common/js/bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			.container-fluid {
				padding: 0;
			}
			
			input,
			button {
				border: 0;
				outline: none;
			}
			
			.vip_msg_add input {
				padding-left: 0.277777rem;
			}
			
			.container-fluid ul {
				padding-top: 0.277777rem;
				margin-bottom: 2.777777rem;
			}
			
			.container-fluid ul li {
				padding-left: 0.416666rem;
				padding-right: 0.416666rem;
			}
			
			.header {
				box-shadow: 0.069444rem 0.069444rem 0.069444rem #b3b3b3;
			}
		</style>
	</head>

	<body style="background-color: #F5F5F5;">
		<div class="header">
			<a href="javascript:history.go(-1)" class="glyphicon glyphicon-menu-left f28 col-xs-4" style="text-align: left;"></a>
			<span class="f28 col-xs-4" style="text-align: center;">免费注册</span>
			<!--<span class="f28 col-xs-4" style="text-align: right;">会员认证</span>-->
		</div>
		<div class="container-fluid">
			<ul>
				<li class="vip_msg_add"> <span>*用户名:</span><input style="border: 0;" type="text" name="" id="name" value="" placeholder="请输入用户名" /></li>
				<li class="vip_msg_add"> <span>*登录密码:</span><input style="border: 0;" type="password" name="" id="pwd" value="" placeholder="登录使用" /></li>
				<li class="vip_msg_add"> <span>*确认密码:</span><input style="border: 0;" type="password" name="" id="repwd" value="" placeholder="请再次输入密码" /></li>
				<li class="vip_msg_add"> <span>*支付密码:</span><input style="border: 0;" maxlength="6" type="password" name="" id="paypwd1" value="" placeholder="仁和币支付使用" /></li>
				<li class="vip_msg_add"> <span>*确认支付密码:</span><input style="border: 0;" maxlength="6" type="password" name="" id="paypwd2" value="" placeholder="请再次输入支付密码" /></li>
				<li class="vip_msg_add"> <span>*手机号码:</span><input style="border: 0;" type="text" name="phone" id="phone" value="" placeholder="请输入手机号码" /></li>
				<li class="vip_msg_add"> <span>*邮箱:</span><input style="border: 0;" type="text" name="" id="myEmial" value="" placeholder="找回密码使用" /></li>
				<li class="vip_msg_add"> <span>感恩号:</span><input style="border: 0;" type="text" name="" id="ganhao" value="" placeholder="请输入感恩号" /></li>
				<li class="vip_msg_add"> <span>*动态码:</span><input style="border: 0;" type="text" name="" id="dongTai" value="" placeholder="请输入动态码" /><button style="background: red;color: white;border: 0;border-radius:1rem ;float: right;margin-right: .2rem;" id="getBtn">免费获取</button></li>
			</ul>

			<!--<p>会员费用：199.00(元/年)</p>-->
			<p style="position: fixed;bottom: 0;width: 100%;margin: 0;;"><button class="add_btn">确定</button></p>
		</div>
		<script src="../../../js/jquery-2.2.3.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var local = 'http://47.104.13.109/member-service';
			var namestatus = false;
			emailstatus = false;
			$(function() {
				//验证用户名
				$("#name").on("blur", function() {
						var name = $("#name").val();
						if($("#name").val().length < 6){
							alert("抱歉用户名最少为6位！");
							$("#name").val("");
						}
						if(name) {
							$.ajax({
								type: "GET",
								url: local + '/register/check-username',
								async: false,
								data: {
									'username': name
								},
								success: function(res) {
									if(res) {
										namestatus = res;
										alert("该用户名已存在！！！");
										$("#name").val("");
									}
									console.log(res);
								},
								error: function(error) {
									console.log(error);
									var s = JSON.parse(error.responseText);
									alert(s.error_message);
								}
							});

						}
					})
					//验证邮箱
				$("#myEmial").on("blur", function() {
						var email = $("#myEmial").val();
						if(email) {
							$.ajax({
								type: "get",
								url: local + '/register/check-email',
								async: false,
								data: {
									'email': email
								},
								success: function(res) {
									if(res) {
										emailstatus = res;
										alert("该邮箱已存在！！！");
										$("#myEmial").val("");
									}
									console.log(res);
								},
								error: function(error) {
									console.log(error);
									var s = JSON.parse(error.responseText);
									alert(s.error_message);
								}
							});

						}
					})
					//验证密码
				$("#repwd").on("blur", function() {
					var pwd = $("#pwd").val(),
						repwd = $("#repwd").val();
					console.log(pwd + repwd);
					if(repwd != pwd) {
						
						alert("两次密码不一致!");
						$("#repwd").val("");
					}
				})
				
				//验证支付密码
				var resz = /^[0-9]*$/;
				$("#paypwd1").on("blur", function(){
					if (!resz.test($("#paypwd1").val())) {
						alert("请输入6位纯数字");
						$("#paypwd1").val("");
					}
				})
				$("#paypwd2").on("blur", function() {
						var pwd = $("#paypwd1").val(),
							repwd = $("#paypwd2").val();
						console.log(pwd + repwd);
						if(repwd != pwd) {
							alert("两次支付密码不一致!");
							$("#paypwd2").val("");
						}
					})
					//获取验证码
				$("#getBtn").on("click", function() {
						var phone = $("#phone").val();
						var reg = /^1[0-9]{10}$/;
						console.log(phone);
						if(reg.test(phone)) {
							time(this)
							$.ajax({
								type: "get",
								url: local + '/register/send-sms-code',
								async: false,
								data: {
									'tel': phone,
								},
								success: function(res) {
									console.log(res);
									$("#getBtn").prop("disabled", 'disabled');
									$("#getBtn").text("请稍等");
									$("#getBtn").css("background", "gray");
								},
								error: function(error) {
									console.log(error);
									var s = JSON.parse(error.responseText);
									alert(s.error_message);
								}
							});
						} else {
							alert("请输入有效的手机号码!");
						}
					})
					//60s重置验证码
					var wait=59;
				function time(o) {
  					if (wait == 0) {
  						o.removeAttribute("disabled");   
 						o.innerHTML="免费获取";
 						$("#getBtn").css("background", "red");
  						 wait = 59;
 					} else { 

   						o.setAttribute("disabled", true);
   					
  						o.innerHTML="重新发送(" + wait + ")";
  						 wait--;
  						 setTimeout(function() {
   							 time(o)
  						 },1000)
 					}
				}
					//验证验证码 注册
				$(".add_btn").on("click", function() {
					var name = $("#name").val(),
						pwd = $("#pwd").val(),
						repwd = $("#repwd").val(),
						phone = $("#phone").val(),
						email = $("#myEmial").val(),
						ganen = $("#ganhao").val(),
						dongtai = $("#dongTai").val();
					paypwd1 = $("#paypwd1").val();
					var datas = {
						'license': 1,
						'username': name,
						'password': pwd,
						'paypwd': paypwd1,
						'tel': phone,
						'email': email,
						'thankNum': ganen,
						'smsCode': dongtai
					};
					if(ganen == null || ganen == "") {
						datas = {
							'license': 1,
							'username': name,
							'password': pwd,
							'paypwd': paypwd1,
							'tel': phone,
							'email': email,
							'smsCode': dongtai
						};
					}

					if(dongtai && phone) {
						//注册
						$.ajax({
							type: "post",
							url: local + '/register/mobile-register',
							async: false,
							data: datas,
							success: function(res) {
								console.log(res);
							
								$.ajax({
						type: "get",
						url: local + '/auth/static-login',
						async: true,
						data: {
							'username': name,
							'password': pwd,
							'remember': 1,
						},
						success: function(res) {
							console.log(res);
							if(res.islogin) {
								//								if($.cookie("tokenRh")){
								$.cookie('tokenReztApp', res.token, {
									expires: 7,
									path: '/'
								});
								$.cookie("tokenRh", res.token, {
									expires: 7,
									path: '/'
								});
								$.cookie('memberId', res.id, {
									expires: 7,
									path: '/'
								});
								$.cookie('roleId', res.roleList[0].id, {
									expires: 7,
									path: '/'
								});
								alert("恭喜您，注册成功！");
								window.location.href = "../../../view/coalition/colalition.html";
							} else {
								alert("账号或密码错误！！！");
							}
						},
						error: function(error) {
							var errors = JSON.parse(error.responseText);
							console.log(errors)
							errors = errors.error_message.replace(":", "");
							alert(errors);
						}
					});
							},
							error: function(error) {
								console.log(error); 
								alert(error.responseJSON.error_message);
							}
						});
					} else {
						alert("请补全信息!");
					}
				})

			})
		</script>
	</body>

</html>